import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/route/application.dart';
import 'package:appflutterhomeschool/route/routes.dart';
import 'package:appflutterhomeschool/ui/widgets/letter/letter_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/my_app_bar.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/notice_tab_widget.dart';
import 'package:appflutterhomeschool/utils/utils.dart';
import 'package:appflutterhomeschool/view_model/letter/letter_view_model.dart';
import 'package:appflutterhomeschool/view_model/my_app_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

///信件页面
class LetterPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    MyAppViewModel myAppViewModel = Provider.of<MyAppViewModel>(context);
    return ProviderWidget<LetterViewModel>(
      model: LetterViewModel(context, myAppViewModel),
      onModelReady: (value) => value.initView(),
      builder: (context, viewModel, child) {
        myAppViewModel.letterViewModel = viewModel;
        return Scaffold(
          backgroundColor: Colors.white,
          appBar: MyAppBar(
            finishBool: true,
            title: myAppViewModel.name,
            fontWeight: FontWeight.bold,
            onTapRight: viewModel.onTapOpenScreen,
            onTapLeft: () => Application()
                .navigatePushToPage(context, Routes.switchClassesPage, {}),
          ),
          body: SingleChildScrollView(
            child: Column(
              children: <Widget>[
                NoticeTabWidget(
                  //未读还是已读
                  unreadBool: viewModel.unreadBool,
                  //未读还是已读事件
                  unreadBoolOnTap: viewModel.unreadBoolOnTap,
                  //是否显示
                  openScreen: viewModel.openScreen,
                  listTab: viewModel.listTab,
                  getIndex: (index) => viewModel.tapModelOnTap(index),
                ),
                LetterTopWidget(),
                LetterListUserWidget(),
              ],
            ),
          ),
          floatingActionButton: GestureDetector(
            onTap: () => Application().navigatePushToPage(
                context, Routes.custumNotificationsPage, {"pageTag": 3}),
            child: Image.asset(
              Utils.getImgPath("xinjian"),
              width: ScreenUtil().setWidth(103),
              height: ScreenUtil().setWidth(103),
            ),
          ),
        );
      },
    );
  }
}
